/**
 * 
 */
package org.shark.jdbcTemplateTool.binding;

import java.lang.reflect.Proxy;
import java.util.Map;

import com.google.common.collect.Maps;

/**
 * @author lenovo
 * @description
 * @date 2016年8月19日
 */
public class DaoProxyFactory<T> {

	private static Map<Class<?>, Object> mapDaoBean = Maps.newConcurrentMap();

	@SuppressWarnings("unchecked")
	public static <T> T newInstance(Class<T> methodInterface) {
		if (!mapDaoBean.containsKey(methodInterface)) {
			final DaoProxy<T> methodProxy = new DaoProxy<T>(methodInterface);
			T obj = (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
					new Class[] { methodInterface }, methodProxy);
			mapDaoBean.put(methodInterface.getClass(), obj);
		}
		return (T)mapDaoBean.get(methodInterface.getClass());
	}

}
